<?php


namespace app\admin\controller;

use app\admin\model\Permission as PermissionModel;
use app\admin\validate\Permission as PermissionValidate;
use app\common\utils\TreeUtil;

class Permission extends Base
{
    protected function _initialize()
    {
        //如果要检测token,就调用父类_initialize方法
//        parent::_initialize();
    }

    public function index()
    {
//        $permission = TreeUtil::listToTreeMulti(, 0, 'id', 'pid', 'children');
        $data['data'] = PermissionModel::all();
        $data['total'] = PermissionModel::count();
        return $this->ok($data);
    }

    public function save()
    {
        (new PermissionValidate())->goCheck();
        $params = input();
//        echo "<pre>";
//        print_r($params);die;
        //$params['img']是url字符串

        //创建顶级分类,或者创建某分类的子分类
        PermissionModel::create($params, true);
        return $this->ok([], '创建权限成功');
    }
}